package com.yaorange.module.system.service.impl;

import com.yaorange.module.system.repository.SysUserRoleRepository;
import com.yaorange.module.system.service.SysUserRoleService;
import com.yaorange.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SysUserRoleServiceImpl implements SysUserRoleService {

    @Autowired
    private SysUserRoleRepository sysUserRoleRepository;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addRelation(Long userId, List<Long> roleIds) {
        sysUserRoleRepository.deleteRelationByUserId(userId);
        if(roleIds!=null && roleIds.size()>0) {
            sysUserRoleRepository.insertRelation(userId, roleIds);
        }
    }

    @Override
    public List<Long> getRoleIdByUserId(Long userId) {
        return sysUserRoleRepository.selectRoleIdsByUserId(userId);
    }

    @Override
    public Long getUserTotalByRoleId(Long roleId) {

        return sysUserRoleRepository.selectTotalByRoleId(roleId);
    }


}
